<template>
	<view class="page">
		<view class="my">
			<u-row>
				<u-col span="3">
					<view class="avatar">

					</view>
				</u-col>
				<u-col span="8">
					
					<view class="information" @click="goto('/pages/order/order')">

					</view>
				</u-col>
				<u-col span="1">
					<view>
						<svg t="1712070090414" class="icon" viewBox="0 0 1024 1024" version="1.1"
							xmlns="http://www.w3.org/2000/svg" p-id="4249" width="32" height="32">
							<path
								d="M283.648 174.081l57.225-59.008 399.479 396.929-399.476 396.924-57.228-59.004 335.872-337.92z"
								fill="#bfbfbf" p-id="4250"></path>
						</svg>
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="wallet">
			<div style="height: 5rpx;"></div>
			<view class="lastRecharge">
				
				<p>成功充值5000元</p>
				<p>2024年 4月 1日</p>
			</view>
			<h2>￥ {{balance * 1000}}</h2>

			<u-button type="primary" hair-line="false"  @click="goto('/pages/recharge/recharge')" style="background-color: rgb(180, 168, 254); width: 400rpx;">我要充值</u-button>
		</view>
		<view class="block" style="height: 400rpx;">

		</view>
		<button type="primary" @click="goto('/pages/login/login')" plain="true">退出登录</button>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: null,
				buyer: {
					tele: null,
					password: null,
					mpanyName: null,
					unifiedCreditCode: null,
					qualificationCertificateIma: null,
					avatarImage: null,
					buyerAccountrStatus: null,
					balance: null,
					address: null,
					token: null,
				},
				balance: 520,
				token: null,
			}
		},
		created() {
			this.recordToken();
		},
		methods: {
			
			/**
			 * 获取JWT
			 */
			recordToken() {
				this.token = localStorage.getItem('token');
				console.log(this.token);
				this.getBuyerAccountByTele();
			},
			
			goto(url) {
				uni.navigateTo({
					url: url
				})
			},
			
			/**
			 * 获取余额
			 */
			getBalance() {
				const url = "http://localhost:8088/buyer-account/balance";
				uni.request({
					url: url,
					method: 'GET',
					header: {
						'content-type': 'application/json',
						'token': this.token
					},
					success: (res) => {
						this.balance = res.data.data;
						console.log(this.balance);
					},
					fail: (err) => {
						console.error('获取余额失败：', err);
					}
				});
			},

			/**
			 * 根据电话查询用户信息
			 */
			getBuyerAccountByTele(){
				const url = "http://localhost:8088/buyer-home/information";
				uni.request({
					url: url,
					method: 'GET',
					header: {
						'content-type': 'application/json',
						'token': this.token
					},
					success: (res) => {
						this.buyer = res.data.data;
						console.log(this.buyer);
					},
					fail: (err) => {
						console.error('获取首页展示的商品列表请求失败：', err);
					}
				});
				this.getBalance();
			},
		}
	}
</script>


<style lang="scss">
	.my {
		height: 150rpx;
		margin-top: 50rpx;
		margin-bottom: 50rpx;

		.avatar {
			height: 150rpx;
			display: flex;
			justify-content: center;
		}

		.information {
			margin-top: 10rpx;
			height: 150rpx;
		}
	}

	.wallet {
		justify-content: center;
		color: #fff;
		width: 650rpx;
		height: 350rpx;
		background-color: rgb(52, 46, 55);
		border-radius: 20px;
		padding: 0 50rpx;

		.lastRecharge {
			display: flex;
			justify-content: space-between;
			margin: 50rpx 0;
		}
		
		h2 {
			margin-bottom: 30rpx;
		}
	}
</style>